<style lang="scss" scoped="">
  @import '../../styles/variables';


</style>

<template>
  <div>
    <div class="list-bar-tools">
      <div>
        <el-input placeholder="" size="mini" class="list-bar-tools-input" v-model="filter.serviceId"
                  suffix-icon="el-icon-search" clearable="">
          <template slot="prepend">服务Id</template>
        </el-input>
      </div>
    </div>
    <el-table
      :data="nodeList"
      style="width: 100%;border-top:2px solid #ccc;">
      <el-table-column type="expand">
        <template slot-scope="props">
          <div v-if="props.row.parameters.length!==0">
            <h5>服务参数</h5>
            <el-form label-position="left" inline v-for="(param,index) in props.row.parameters" :key="'p'+index"
                     class="table-expand-form">
              <el-form-item label="名称">
                <span>{{param.name }}</span>
              </el-form-item>
              <el-form-item label="标题" v-if="param.title">
                <span>{{param.title }}</span>
              </el-form-item>
              <el-form-item label="是否数组">
                <el-tag size="mini">{{param.array ? '是' : '否'}}</el-tag>
              </el-form-item>
              <el-form-item label="是否必须">
                <el-tag size="mini">{{param.required ? '是' : '否'}}</el-tag>
              </el-form-item>
              <el-form-item label="参数类型">
                <span>{{param.type }}</span>
              </el-form-item>
              <el-form-item label="集合类型" v-if="param.collectionType">
                <span>{{param.collectionType }}</span>
              </el-form-item>
              <el-form-item label="描述" v-if="param.description">
                <span>{{param.description }}</span>
              </el-form-item>
            </el-form>
          </div>
          <div v-if="props.row.results.length!==0">
            <h5>返回结果</h5>
            <el-form label-position="left" inline v-for="(param,index) in props.row.results" :key="'r'+index"
                     class="table-expand-form">
              <el-form-item label="名称">
                <span>{{param.name }}</span>
              </el-form-item>
              <el-form-item label="标题" v-if="param.title">
                <span>{{param.title }}</span>
              </el-form-item>
              <el-form-item label="是否数组">
                <el-tag size="mini">{{param.array ? '是' : '否'}}</el-tag>
              </el-form-item>
              <el-form-item label="是否必须">
                <el-tag size="mini">{{param.required ? '是' : '否'}}</el-tag>
              </el-form-item>
              <el-form-item label="类型">
                <span>{{param.type }}</span>
              </el-form-item>
              <el-form-item label="集合类型" v-if="param.collectionType">
                <span>{{param.collectionType }}</span>
              </el-form-item>
              <el-form-item label="描述" v-if="param.description">
                <span>{{param.description }}</span>
              </el-form-item>
            </el-form>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="serviceId"
        label="服务Id">
      </el-table-column>
      <el-table-column
        label="服务参数">
        <template slot-scope="scope">
          <div v-if="scope.row.parameters.length===0">无</div>
          <div v-else>
            <el-tag size="mini" v-for="(param,index) in scope.row.parameters" :key="index" style="margin-right:5px;">
              {{param.name}}
            </el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="服务结果">
        <template slot-scope="scope">
          <div v-if="scope.row.results.length===0">无</div>
          <div v-else>
            <el-tag size="mini" v-for="(param,index) in scope.row.results" :key="index" style="margin-right:5px;">
              {{param.name}}
            </el-tag>
          </div>
        </template>
      </el-table-column>

    </el-table>

    <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="1"
        :page-sizes="[10, 50, 100]"
        :page-size="filter.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="nodeCount">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import utils from '@/utils/utils';
  import {nodeService} from '@/api/index';
  import {mapGetters} from 'vuex';

  export default {
    data() {
      return {
        filter: {
          pageNo: 1,
          pageSize: 10,
          start: 0,
          serviceId: '',
          nodeId: ''
        },
        nodeCount: 0,
        nodeList: [],
        serviceId: ''
      };
    },
    computed: {
      currentNodeId() {
        return this.$route.params.nodeId;
      }
    },
    watch: {
      'filter': {
        handler: function () {
          this.getNodeList();
        },
        deep: true
      }
    },
    components: {},
    methods: {
      handleCurrentChange(currentPageNo) {
        this.filter.start = (currentPageNo - 1) * this.filter.pageSize;
      },
      handleSizeChange(pageSize) {
        this.filter.pageSize = pageSize;
        localStorage.setItem('node-service-page-size', pageSize);
      },
      getNodeList() {
        if (!this.currentNodeId) {
          return false;
        }
        nodeService.getServicePage(this.filter).then(res => {
          this.nodeCount = res.data.total;
          this.nodeList = res.data.rows;
        });
      }
    },
    created() {
      let oldPageSize = localStorage.getItem('node-service-page-size');
      if (!oldPageSize) {
        oldPageSize = 10;
      }
      this.filter.pageSize = Math.floor(oldPageSize);
    },
    mounted() {
      this.filter.nodeId = this.currentNodeId;

    }
  };
</script>
